class Solution {
    public:
        int findSubstringInWraproundString(string s) {
            int n = s.size();
            vector<int> dp(n,1);
            int hash[26];
            dp[0] = 1;
            hash[s[0]-'a'] = 1;
            for(int i = 1 ; i < n ; i++){
                if(s[i] == s[i-1]+1 ||(s[i] == 'a' && s[i-1] == 'z')){
                    dp[i] += dp[i-1];
                }
                if(hash[s[i]-'a'] < dp[i])  hash[s[i]-'a'] = dp[i];
            }
            int ret = 0;
            for(int i = 0 ; i < 26 ; i++){
                ret += hash[i];
            }
            return ret;
        }
    };